package com.example.yuejian.yuejian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.base.BaseActivity;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.EditNickname;
import com.example.yuejian.yuejian.model.UserModel;

public class EditnameActivity extends BaseActivity {
    private EditText username;
    private Button confirm;
    private  ImageView btn_back;
    private ModleListener <EditNickname> listener=new ModleListener<EditNickname>() {
        @Override
        public void onResponse(EditNickname o) {
            EditNickname res =o;
            if (!"1".equals(res.getRetCode()))
            {
                Toast.makeText(EditnameActivity.this,res.getRetMsg(),Toast.LENGTH_SHORT).show();
                finish();
            }
            else
            {
                Toast.makeText(EditnameActivity.this,res.getRetMsg(),Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_editname);
        back();
        Intent intent=getIntent();
        String name=intent.getStringExtra("user_name");
        username=(EditText)findViewById(R.id.edit_username);
        confirm=(Button)findViewById(R.id.editname_confirm_btn) ;
        username.setText(name);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserModel userModel=new UserModel();
                userModel.EditNickName(getUser_id(),username.getText().toString(),listener);

            }
        });
    }
    private void back()
    {
        btn_back=(ImageView)findViewById(R.id.imgBtn_edit_nickname_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
}
